package sort;

import java.util.Arrays;

//选择排序
public class SelectionSort {
    public static void main(String[] args) {
//        int ary[] = {1, 3, 9, 56, 87, 49, 35};
        /*  //int整型升序
        for (int i = 0; i < ary.length - 1; i++) {  //i表示对i位置求最小值
            int min = i; //min表示最小值的下标
            for (int j = i+1; j < ary.length; j++) {
                if (ary[j] < ary[min]) {
                    min = j;
                }
            }
            int temp = ary[i];
            ary[i] = ary[min];
            ary[min] = temp;
        }*/

        //int整型降序
        /*for (int i = 0; i < ary.length-1; i++) {
            int max = i;
            for (int j = i+1; j < ary.length; j++) {
                if (ary[j] > ary[max]){
                    max = j;
                }
            }
            int temp = ary[max];
            ary[max] = ary[i];
            ary[i] = temp;
        }*/

        //String数组降序
        String ary[] = {"tom","张飒","aion","fuck","zuie","米恩"};
        for (int i = 0; i < ary.length-1; i++) {
            int max = i;
            for (int j = i+1; j < ary.length; j++) {
                if (ary[j].compareTo(ary[max]) < 0){
                    max = j;
                }
            }
            String temp = ary[max];
            ary[max] = ary[i];
            ary[i] = temp;
        }
        System.out.println(Arrays.toString(ary));
    }
}
